//
//  BYLoginControllerViewController.m
//  School+
//
//  Created by Sean Sebastian on 3/10/16.
//  Copyright © 2016 Sean Sebastian. All rights reserved.
//

#import "BYLoginControllerViewController.h"
#import "BYMainViewController.h"

#import "BYLoginView.h"
#import "BYRegisterViewController.h"
#import "BYWelcomeViewController.h"

#import "BYAdminLoginViewController.h"

#import "UserAccount.h"
#import "AppDelegate.h"


@interface BYLoginControllerViewController () <LoginViewDelegate>

@end

@implementation BYLoginControllerViewController

// 当实现了这个方法，并且给view设置值，就不会再从其他地方加载view，xib、storyboard
- (void)loadView
{
    BYLoginView *view = [[BYLoginView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    view.delegate = self;
    self.view = view;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"后台管理" style:UIBarButtonItemStyleDone target:self action:@selector(adminLoginClick)];
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"click");
}

- (void)loginViewLoginClick
{
    printf(__FUNCTION__);
    [self dismissViewControllerAnimated:true completion:^{
        // 跳转到欢迎界面，从欢迎界面中再次加载HomeView
        
//        [(AppDelegate *)[UIApplication sharedApplication].delegate switchRootController:NO];
         [(AppDelegate *)[UIApplication sharedApplication].delegate toTheMain];
        
    }];
}


- (void)loginViewRegistClick
{
    BYRegisterViewController *vc = [[BYRegisterViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    vc.title = @"注册";
    [self presentViewController:nav animated:YES completion:^{
        //        NSLog(@"presentedViewController = %@",self.presentedViewController);
    }];
}

- (void)adminLoginClick
{
    BYAdminLoginViewController *vc = [[BYAdminLoginViewController alloc] init];
    vc.title = @"后台管理";
    
    [self.navigationController pushViewController:vc animated:YES];
    
//    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
//    [self presentViewController:nav animated:YES completion:nil];
}

@end
